<?php
namespace app\admin\controller;

use \think\Controller;
use think\Request;
use think\Session;

class User extends Controller
{
    //類數據容器
    protected $data;

    public function childList()
    {
        $uId = Request::instance()->param('u_id', session('userinfo.u_id'));

        $this->assign('u_id', $uId);
        return $this->fetch();
    }

    /**
     * 添加數據
     * @return mixed
     */
    public function add()
    {
        $this->data['where'] = array('id'=>Session::get('userinfo')['role_id']);
        $this->data['field'] = 'id,level';
        $this->data['data']  = model('Role')->getOneData($this->data);
        $this->data['where'] = array('role_status'=>'0','level'=>array('>',$this->data['data']['level']));
        $this->data['field'] = 'id,role_name';
        $this->data['data'] = model('Role')->lists($this->data);
        $this->assign('data',$this->data['data']);
        return $this->fetch();
    }

    /**
     * 編輯用戶
     * @return mixed
     */
    public function edit($u_id)
    {
        $this->data['where'] = array('id'=>Session::get('userinfo')['role_id']);
        $this->data['field'] = 'id,level';
        $this->data['data']  = model('Role')->getOneData($this->data);
        $this->data['where'] = array('role_status'=>'0');
        $this->data['field'] = 'id,role_name';
        $this->data['data'] = model('Role')->lists($this->data);
        $this->data['where'] = array('u_id'=>$u_id);
        $this->data['field'] = 'u_id,u_name,role_id';
        $this->data['user_data'] = model('user')->getOneData($this->data);
        $this->assign('data',$this->data['data']);
        $this->assign('userData',$this->data['user_data']);
        return $this->fetch();
    }
}
